fun main(args: Array<String>) {
    println("HelloWorld")
    foo{
        99
    }

    foo1 { 
        println("function lamda")
    }

    val info1 = SubInfo("20210329001", 1032910478, "推送1")
    val info2 = SubInfo("20210329002", 1032910477, "推送2")
    val info3 = SubInfo("20210329003", 1032910471, "推送3")
    val info4 = SubInfo("20210329003", 1032910472, "推送3")
    val info5 = SubInfo("20210329002", 1032910473, "推送2")
    val info6 = SubInfo("20210329001", 1032910474, "推送1")
    val info7 = SubInfo("20210329002", 1032910475, "推送2")
    val info8 = SubInfo("20210329001", 1032910476, "推送1")
    val info9 = SubInfo("20210329003", 1032910479, "推送3")
    val info10 = SubInfo("20210329001", 1032910470, "推送1")

    val list = listOf(info1,info2,info3,info4,info5,info6,info7,info8,info9,info10)
    list.subList(list.size-4,list.size).forEach{info->
        println("{msgID:${info.msgID}, content:${info.content}, pushTime: ${info.pushTime}}")
    }

    val list2 = mutableListOf<SubInfo>()
    var tempInfo:SubInfo
    for (index in list.indices){
        val info = list[index]
        tempInfo = info
        println("index=$index, {msgID:${info.msgID}, content:${info.content}, pushTime: ${info.pushTime}}")
        for(i in index..list.size-1){
            val infoS = list[i]
            if(tempInfo.msgID == infoS.msgID && infoS.pushTime>tempInfo.pushTime){
                tempInfo = infoS
            }
        }
        val find = list2.find{ it.msgID==tempInfo.msgID }
        if(find == null){
            list2.add(tempInfo)
        }
    }

    list2.sortByDescending { it.pushTime }
    list2.forEach{
        println(" {msgID:${it.msgID}, content:${it.content}, pushTime: ${it.pushTime}}")
    }
}

fun foo(block: (() -> Int)?=null) {
    val promise = block?:{
        10
    }

    println(promise())
}

fun foo1(block:()->Unit){
    block()
}

data class SubInfo(val msgID: String, val pushTime: Long, val content: String)
